package com.zyf.article.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zyf.article.dao.ArticleDao;
import com.zyf.article.pojo.Article;
import com.zyf.article.service.ArticleService;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CachePut;
import org.springframework.stereotype.Service;

@Service
@CacheConfig(cacheNames = "article_")
public class ArticleServiceImpl extends ServiceImpl<ArticleDao, Article> implements ArticleService {
    @Autowired
    ArticleDao articleDao;

    /**
     * 文章审核
     * //     * @param id
     */
    @CachePut(key = "#id")
    public Object examine(String state, String id) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("id",id);
        Article article = articleDao.selectById(queryWrapper);
        articleDao.examine(state, id);
        return article;
    }

    /**
     * 点赞
     * //     * @param id 文章ID
     *
     * @return
     */
    @CachePut(key = "#id")
    public Object updateThumbup(String id) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("id",id);
        Article article = articleDao.selectById(queryWrapper);
         articleDao.updateThumbup(id);
         return article;
    }
}
